package com.airtight.game;

import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity{

    private MyGLSurfaceView glSurfaceView;

    @Override
    public void onCreate(Bundle SavedInstanceState){
        super.onCreate(SavedInstanceState);
        int[] coords = getRatio();
        GameState gameState = new GameState(coords);
        glSurfaceView = new MyGLSurfaceView(this, gameState);
        glSurfaceView.setPreserveEGLContextOnPause(true);
        setContentView(glSurfaceView);
    }
    //Handles the Activity Life Cycle for OpenGL

    @Override
    public void onPause(){
        super.onPause();
        if(glSurfaceView.rendered){
            glSurfaceView.onPause();
        }
    }

    @Override
    public void onResume(){
        super.onResume();
        if(glSurfaceView.rendered){
            glSurfaceView.onResume();
        }
        hideBars();
    }

    @Override
    public void onBackPressed() {
        glSurfaceView.Renderer.getScreenManager().getScreen().onBackPressed();
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public void hideBars(){
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }

    public int[] getRatio(){
        Point point = new Point();
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){
            this.getWindowManager().getDefaultDisplay().getRealSize(point);
        }
        else{
            this.getWindowManager().getDefaultDisplay().getSize(point);
        }

        //Log.d("y", ""+point.y);
        //Log.d("x", ""+point.x);
        int x =  point.x;
        int y =  point.y;
        Toast.makeText(this,""+x+" "+y,Toast.LENGTH_SHORT).show();
        return new int[] {x,y};
    }
}